<?php

$html = array();
$mod = $_GET['mod'];
if ($mod == 'updatePwdByPhone') {
    if ($row == 0) {
        $html['callback'] .= "alert(\"网络连接超时\");";
    } else {
        if ($row['code'] == 0) {
            $html['callback'] .= "alert(\"验证码发送成功\");";
            //$(\"#GetpwdForm_uid\").val(" . $row['UpdatePwdByPhoneRsp']['userId'] . ");
        } else {
            $html['callback'] .= "alert(\"" . $row['ExceptionRsp']['msg'] . "\");";
        }
    }
} elseif ($mod == 'addUserContactInfo') {
    if ($status['code'] == 1) {
        if ($row == 0) {
            $html['callback'] .= "alert(\"网络连接超时\");";
        } else {
            if ($row['code'] == 0) {
                $html['callback'] .= "ajaxGet('#addresslist', 'getUserContactInfo', 'account', 'html');$(\".address-form\").hide();$(\".add-address\").parents(\".infolist\").show();";
            } else {
                $html['callback'] .= "alert(\"" . $row['ExceptionRsp']['msg'] . "\");";
            }
        }
    } elseif ($status['code'] == -1) {
        $html['callback'] .= "alert(\"请先的登录\");";
    } elseif ($status['code'] == 0) {
        $html['callback'] .= "alert(\"" . $status['msg'] . "\");";
    }
} elseif ($mod == 'getContactInfo') {
    if ($row == 0) {
        echo "网络连接超时";
    } else {
        if ($row['code'] == 0) {
            
        } else {
            echo $row['ExceptionRsp']['msg'];
        }
    }
} elseif ($mod == 'getUserContactInfo') {
    if ($row == 0) {
        echo "网络连接超时";
    } else {
        if ($row['code'] == 0) {
            if ($row['GetUserContactInfoRsp']['list']) {
                if ($_GET['t'] == 'order') {
                    foreach ($row['GetUserContactInfoRsp']['list'] as $key => $value) {
                        $html['content'].= '<li class="cl"><label class="radio"><input type="radio" value="' . $value['id'] . '" name="OrderForm[userContactInfoId]"';
                        if ($value['defaultAddress'] == 1) {
                            $html['content'] .= ' checked="checked"';
                        }
                        $html['content'] .= '>' . $value['recipients'] . '，' . $value['mobile'] . '，' . $value['province'] . '，' . $value['city'] . '，' . $value['area'] . '，' . $value['street'] . '，' . $value['streetDetail'] . '，' . $value['postalcode'] . '</label></li>';
                    }
                    $html['content'] .= '<li class="cl"><label class="radio"><input type="radio" name="OrderForm[userContactInfoId]" id="otheraddress" value="0"/>其他地址</label></li>';
                } else {
                    foreach ($row['GetUserContactInfoRsp']['list'] as $key => $value) {
                        $html['content'].= '<div class="infolist cols1 cl">';
                        $html['content'] .= '<div class="col cl">';
                        $html['content'] .= '<div class="tit">' . $value['recipients'] . '</div>';
                        $html['content'] .= '<div class="inp cl" style="width:890px;">';
                        $html['content'] .= '<div class="z">' . $value['province'] . '<span class="pipe"></span>' . $value['city'] . '<span class="pipe"></span>' . $value['area'] . '<span class="pipe"></span>' . $value['street'] . '<span class="pipe"></span>' . $value['streetDetail'] . '<span class="lm18">' . $value['mobile'] . '</span><span class="pipe"></span>' . $value['postalcode'] . '</div>';
                        $html['content'] .= '<div class="y">';
                        
                        if ($value['defaultAddress'] == 1) {
                            $html['content'] .= '<span class="rm50 c_b">';
                            $html['content'] .= '默认地址';
                            $html['content'] .= '</span>';
                        } else {
                            $html['content'] .= '<a href="javascript:void(0);" default-id="' . $value['id'] . '" class="c_b setting_default set-def rm50" onclick="changeContactDefault('. $value['id'] .');">设为默认地址</a>';
                        }
                        //<a href="' . $value['id'] . '" class="c_b">编辑</a><span class="pipe c_b">|</span>
                        $html['content'] .= '<a href="javascript:void(0);" class="c_b" address-id="' . $value['id'] . '">删除</a>';
                        $html['content'] .= '</div>';
                        $html['content'] .= '</div>';
                        $html['content'] .= '</div>';
                        $html['content'] .= '</div>';
                    }

                    $html['content'] .= '<div class="infolist cols1 cl clbd_b">';
                    $html['content'] .= '<div class="col cl">';
                    $html['content'] .= '<div class="tit"></div>';
                    $html['content'] .= '<div class="inp cl"><a href="javascript:void(0);" class="c_b add-address">添加新地址</a></div>';
                    $html['content'] .= '</div>';
                    $html['content'] .= '</div>';
                }
            } else {
                $html['content'] .= '<div class="infolist cols1 cl clbd_b">';
                $html['content'] .= '<div class="col cl">';
                $html['content'] .= '<div class="tit"></div>';
                $html['content'] .= '<div class="inp cl">暂无收货地址，马上<a href="javascript:void(0);" class="c_b add-address">添加新地址</a></div>';
                $html['content'] .= '</div>';
                $html['content'] .= '</div>';
            }

            if ($_GET['t'] == 'order') {
                $html['callback'] .= "$(\"input[name='OrderForm[userContactInfoId]']:radio\").click(function() { if ($(this).val() == '0'){ $(\"#newaddress\").show();} else { $(\"#newaddress\").hide();}});";
                $html['callback'] .= "delAddress('order');";
            } else {
                $html['callback'] .= "$(\".add-address\").click(function() { $(this).parents(\".infolist\").hide();$(\".address-form\").show();});";
                $html['callback'] .= "delAddress();";
                $html['callback'] .= "$(\"#address-form\")[0].reset();";
                $html['callback'] .= '$("#addresslist").find(".infolist").hover(
                        function() {
                            $(this).find(".set-def").show();
                        },
                        function() {
                            $(this).find(".set-def").hide();
                        }
                );';
            }
        } else {
            $html['content'] .= '<div class="infolist cols1 cl clbd_b">';
            $html['content'] .= '<div class="col cl">';
            $html['content'] .= '<div class="tit"></div>';
            $html['content'] .= '<div class="inp cl">' . $row['ExceptionRsp']['msg'] . '</div>';
            $html['content'] .= '</div>';
            $html['content'] .= '</div>';
        }
    }
} elseif ($mod == 'delContactInfo') {
    if ($status['code'] == 1) {
        if ($row == 0) {
            $html['callback'] .= "alert(\"网络连接超时\");";
        } else {
            if ($row['code'] == 0) {
                $html['callback'] .= "ajaxGet('#addresslist', 'getUserContactInfo";
                $html['callback'] .= $_GET['t'] == "order" ? "&t=order" : "";
                $html['callback'] .= "' , 'account', 'html');";
            } else {
                $html['callback'] .= "alert(\"" . $row['ExceptionRsp']['msg'] . "\");";
            }
        }
    } elseif ($status['code'] == -1) {
        $html['callback'] .= "alert(\"请先登录\");";
    } elseif ($status['code'] == 0) {
        $html['callback'] .= "alert(\"" . $status['msg'] . "\");";
    }
} elseif ($mod == 'addUserCart') {
    if ($status['code'] == 1) {
        if ($row == 0) {
            $html['callback'] .= "alert(\"网络连接超时\");";
        } else {
            if ($row['code'] == 0) {
                $html['callback'] .= "ajaxGet('.store-list-box', 'getUserCart', 'account', 'html');";
                $html['callback'] .= '$(".store-list-out").show();';
            } else {
                $html['callback'] .= "alert(\"" . $row['ExceptionRsp']['msg'] . "\");";
            }
        }
    } elseif ($status['code'] == -1) {
        $html['callback'] .= "alert(\"请先登录\");";
    } elseif ($status['code'] == 0) {
        $html['callback'] .= "alert(\"" . $status['msg'] . "\");";
    }
} elseif ($mod == 'addBuyerCoupons') {
    if ($status['code'] == 1) {
        if ($row == 0) {
            $html['content'] .= "网络连接超时";
        } else {
            if ($row['code'] == 0) {
                $html['content'] .= '红包领取成功<br/><a href="javascript:void(0);" onclick="hideWindow();">关闭</a>';
                $html['callback'] .= '$(".hb-img").removeClass("hb_close");';
                $html['callback'] .= '$(".hb-img").addClass("hb_open");';
                $html['callback'] .= '$(".hb-img").removeAttr("onclick");';
            } else {
                $html['content'] .= $row['ExceptionRsp']['msg'];
            }
        }
    } elseif ($status['code'] == -1) {
        $html['content'] .= "请先登录";
    } elseif ($status['code'] == 0) {
        $html['content'] .= $status['msg'];
    }
} elseif ($mod == 'delUserCart') {
    if ($status['code'] == 1) {
        if ($row == 0) {
            $html['callback'] .= "alert(\"网络连接超时\");";
        } else {
            if ($row['code'] == 0) {
                $html['callback'] .= "ajaxGet('.store-list-box', 'getUserCart";
                $html['callback'] .= $_GET['t'] == "order" ? "&t=order" : "";
                $html['callback'] .= "' , 'account', 'html');";
            } else {
                $html['callback'] .= "alert(\"" . $row['ExceptionRsp']['msg'] . "\");";
            }
        }
    } elseif ($status['code'] == -1) {
        $html['callback'] .= "alert(\"请先登录\");";
    } elseif ($status['code'] == 0) {
        $html['callback'] .= "alert(\"" . $status['msg'] . "\");";
    }
} elseif ($mod == 'getUserCart') {
    if ($row == 0) {
        $html['content'].= "<li class=\"cl\">网络连接超时</li>";
    } else {
        if ($row['code'] == 0) {
            $cartamoud = count($row['GetUserCartRsp']['buyCartItems']);
            $cartprices = 0;
            if ($cartamoud > 0) {
                if ($_GET['t'] == 'order') {
                    foreach ($row['GetUserCartRsp']['buyCartItems'] as $key => $value) {
                        $skuarr = array();
                        foreach ($value['productSkuValue'] as $key2 => $sku) {
                            $skuarr[] = $sku['skuValue'];
                        }
                        $html['content'].= '<li class="cl list" cart-id="' . $value['id'] . '"><div class="img z"><img align="absmiddle" src="' . $value['img'] . '"></div><div class="wt foodname z"><a href="' . $this->createUrl('site/product', array('id' => $value['productSkuId'])) . '" target="_blank">' . $value['productName'] . '</a><div class="skuinfo">' . implode(' - ', $skuarr) . '</div></div><div class="wt foodprice z c_b">￥' . number_format($value['skuPrice'], 2) . '</div><div class="wt foodcount z cl"><a class="z less" href="javascript:void(0);"><span class="cmicons"></span></a><input class="z less_incr_amound" type="text" value="' . $value['amount'] . '" name="OrderForm[amount][]"><a class="z incr" href="javascript:void(0);"><span class="cmicons"></span></a></div><div class="wt foodsprice z cl">￥' . number_format($value['skuPrice'] * $value['amount'], 2) . '</div><div class="wt operation z"><!--<a href="#">添加到收藏夹</a><span class="pipe">|</span>--><a href="javascript:void(0);" cart-id="' . $value['id'] . '">删除</a></div></li>';
                        $html['content'] .= "<input type=\"hidden\" name=\"OrderForm[productSkuId][]\" value=\"" . $value['productSkuId'] . "\"/>";
                        $html['content'] .= "<input type=\"hidden\" name=\"OrderForm[id][]\" value=\"" . $value['id'] . "\"/>";
                        $html['content'] .= "<input type=\"hidden\" name=\"OrderForm[sellerId][]\" value=\"" . $value['sellerId'] . "\"/>";
                        $cartprices += $value['skuPrice'] * $value['amount'];
                    }
                    $html['callback'] .= "ChangeAmound();";
                } else {
                    foreach ($row['GetUserCartRsp']['buyCartItems'] as $key => $value) {
                        $sellerIds[] = $value['sellerId'];
                        $productSkuIds[] = $value['productSkuId'];
                        $amounts[] = $value['amount'];
                        $html['content'].= "<li class=\"cl\"><div class=\"z name\"><a href=\"" . $this->createUrl('site/product', array('id' => $value['productSkuId'])) . "\">" . $value['productName'] . "</a></div><div class=\"z count\">￥" . $value['skuPrice'] . " × " . $value['amount'] . "</div><div class=\"z price\">￥" . number_format($value['skuPrice'] * $value['amount'], 2) . "</div><div class=\"z btn\"><a href=\"javascript:void(0);\" class=\"cmicons\" cart-id=\"" . $value['id'] . "\"></a></div></li>";
                        $cartprices += number_format($value['skuPrice'], 2) * $value['amount'];
                    }
                    $html['content'].= "<input type=\"hidden\" name=\"sellerIds[]\" value=\"" . implode(',', $sellerIds) . "\"/>";
                    $html['content'].= "<input type=\"hidden\" name=\"productSkuIds[]\" value=\"" . implode(',', $productSkuIds) . "\"/>";
                    $html['content'].= "<input type=\"hidden\" name=\"amounts[]\" value=\"" . implode(',', $amounts) . "\"/>";
                }
            } else {
                if ($_GET['t'] == 'order') {
                    $html['content'].= "<div class=\"nfl\">";
                    $html['content'].= "<div class=\"f_c altw\">";
                    $html['content'].= "<div id=\"messagetext\" class=\"alert_error\">";
                    $html['content'].= "<p>购物车里没有东西哦<script type=\"text/javascript\" reload=\"1\">//setTimeout(\"window.location.href ='http://wh.whtaxi.com/zp/';\", 3000);</script></p>";
                    $html['content'].= "<p class=\"alert_btnleft\"><a href=\"" . Yii::app()->baseUrl . "\">马上去点餐</a></p>";
                    $html['content'].= "</div>";
                    $html['content'].= "</div>";
                    $html['content'].= "</div>";
                    $html['callback'] .= "$(\".cart-buy-btn\").removeClass('submit_blue').addClass('submit_gray').attr('disabled',true);";
                } else {
                    $html['content'].= "<li class=\"cl\">没有商品</li>";
                }
            }
            $html['callback'] .= "$(\".cart-amound\").html('" . $cartamoud . "');$(\".cart-prices\").html('" . number_format($cartprices, 2) . "');";
            if ($_GET['t'] == 'order') {
                $html['callback'] .= "$(\"#OrderForm_productTotalPrice\").val('" . $cartprices . "');";
                $html['callback'] .= "delCart('order');";
            } else {
                $html['callback'] .= "delCart();";
            }
//            print_r($row);
        } else {
            $html['content'].= "<li class=\"cl\">" . $row['ExceptionRsp']['msg'] . "</li>";
        }
    }
} elseif ($mod == 'updateUserCart') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
            $html['callback'] .= "ajaxGet('.store-list-box', 'getUserCart&t=order' , 'account', 'html');";
        } else {
            $html['callback'].= "alert('" . $row['ExceptionRsp']['msg'] . "');";
        }
    }
} elseif ($mod == 'getBusinessZone') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
            $html['content'] .= '<ul class="zone_ul">';
            foreach ($row['GetAllBusinessZoneRsp']['list'] as $key => $value) {
                $html['content'] .= '<li id="' . $value['id'] . '"><a href="' . $this->createUrl('ajax/ajax', array('mod' => 'setZone', 'id' => $value['id'])) . '">' . $value['zoneName'] . '</a></li>';
            }
            $html['content'] .= '</ul>';
        } else {
            $html['callback'].= "alert('" . $row['ExceptionRsp']['msg'] . "');";
        }
    }
} elseif ($mod == 'getZone') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
            $html['content'] .= $row['GetAllBusinessZoneRsp']['list']['0']['zoneName'];
        } else {
            $html['callback'].= "alert('" . $row['ExceptionRsp']['msg'] . "');";
        }
    }
} elseif ($mod == 'getHeadImg') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
//            $html['callback'].="window.onload = function(){";
            $count = count($row['GetHeadImgListRsp']['list']);
            if($count == 0){
                $html['callback'].='$("#preview").attr("src", "' . Yii::app()->params['smallUrl'] . '");';
                $html['callback'].='$("#preview1").attr("src","' . Yii::app()->params['middleUrl'] . '");';
                $html['callback'].='$("#preview2").attr("src", "' . Yii::app()->params['bigUrl'] . '");';
            }else{
                foreach ($row['GetHeadImgListRsp']['list'] as $key => $value) {
                    if ($value['type'] == 1) {
                        $html['callback'].='$("#preview").attr("src", "' . $value['url'] . '");';
                    } elseif ($value['type'] == 2) {
                        $html['callback'].='$("#preview1").attr("src","' . $value['url'] . '");';
                    } elseif ($value['type'] == 3) {
                        $html['callback'].='$("#preview2").attr("src", "' . $value['url'] . '");';
                    }
                }                
            }
//            $html['callback'].="}";
        } else {
            
        }
    }
} elseif ($mod == 'getHeadImgByType') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
            $count = count($row['GetHeadImgListRsp']['list']);
            if($count == 0){
                $html['callback'].='$("#homemainId").attr("src","'.Yii::app()->params['smallUrl'].'");';                
            }else{
                foreach ($row['GetHeadImgListRsp']['list'] as $key => $value) {
                    $html['callback'].='$("#homemainId").attr("src", "'.$value['url'].'");';                
                }                
            }
        } else {
            
        }
    }
} elseif ($mod == 'getAddressList') {
    if ($row == 0) {
        $html['content'].= "<li class=\"cl\">网络连接超时</li>";
    } else {
        if ($row['code'] == 0) {
            $count = count($row['GetAddressListRsp']['list']);
            $html['content'].= "<option value=0>请选择</option>";
            if ($count > 0) {
                foreach ($row['GetAddressListRsp']['list'] as $key => $value) {
                    $html['content'].= "<option value=" . $value['id'] . ">" . $value['name'] . "</option>";
                }
            }
        } else {
            $html['content'].= "<li class=\"cl\">" . $row['ExceptionRsp']['msg'] . "</li>";
        }
    }
} elseif ($mod == 'closeOrder') {
    $html['content'] .= '<form class="cl" method="POST">';
    $html['content'] .= '<h2 style="text-align:center;">是否要取消此订单？</h2>';
    $html['content'] .= '<div style="text-align:center;" class="tm15">';
    $html['content'] .= '<input id="oksubmit" class="submit submit_blue submit_wpd" type="submit" value="是" name="oksubmit">';
    $html['content'] .= '<input id="canclesubmit" class="submit submit_gray lm18 submit_wpd" type="button" value="否" name="canclesubmit" onclick="hideWindow();">';
    $html['content'] .= '</div>';
    $html['content'] .= '<input type="hidden" name="OrderForm[orderid]" value="' . $row . '"/>';
    $html['content'] .= '</form>';
    $html['callback'] .= 'jQuery(\'body\').on(\'click\',\'#oksubmit\',function(){jQuery.ajax({\'dataType\':\'json\',\'success\':function(json){if (json.callback) {eval(json.callback);}},\'type\':\'POST\',\'url\':\'' . Yii::app()->baseUrl . '/ajax/account/?mod=closeOrderDone\',\'cache\':false,\'data\':jQuery(this).parents("form").serialize()});return false;});';
} elseif ($mod == 'closeOrderDone') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
            $html['callback'].= "alert('取消订单成功');";
            $html['callback'] .= 'window.location.href="'.Yii::app()->baseUrl.'/home"';
        } else {
            $html['callback'].= "alert('" . $row['ExceptionRsp']['msg'] . "');";
        }
    }
} elseif ($mod == 'setDefaultContactInfo') {
    if ($row == 0) {
        $html['callback'].= "alert('网络连接超时');";
    } else {
        if ($row['code'] == 0) {
            $html['callback'].= "ajaxGet('#addresslist', 'getUserContactInfo', 'account', 'html');";            
        } else {
            $html['callback'].= "alert('" . $row['ExceptionRsp']['msg'] . "');";
        }
    }
}
echo CJSON::encode($html);
?>